Conversation
- Introduced regression tests across multiple cache policies (ARC, MFU, MRU, SLRU, TwoQ) to verify that caches with a capacity of 0 correctly reject inserts and maintain expected behavior. - Added a new integration test file for cross-policy invariants to ensure consistent handling of capacity-0 across different cache implementations. - Updated the tests README to include information about the new invariant tests, enhancing documentation clarity.
- Added `evict_lru` method to the ghost list for removing the least recently used key, enhancing eviction capabilities. - Updated ARC and other policies to utilize the new LRU eviction method, ensuring efficient capacity management. - Refined handling of capacity checks in various policies to prevent unnecessary evictions and improve performance. - Adjusted tests to validate the new eviction behavior and ensure consistency across cache implementations.
- Updated operation table in `clock_ring.rs` to use links for method references, improving clarity and navigation. - Changed `HashMap` to `FxHashMap` in documentation for better performance context. - Added `Clone` derive to `Entry` and `ClockRing` structs to enhance usability in concurrent scenarios. - Modified public API methods to accept borrowed keys, allowing for more flexible key types and reducing unnecessary clones. - Improved documentation with concise examples for `clear`, `clear_shrink`, and `approx_bytes` methods, enhancing user understanding.
- Changed `HashMap` to `FxHashMap` in the documentation to reflect performance optimizations. - Enhanced entry and ClockRing struct documentation to clarify key borrowing capabilities. - Added details on lookup methods accepting borrowed keys, improving API usability. - Updated examples and descriptions to align with recent changes in the public API.
- Introduced `Iter`, `IterMut`, `Keys`, `Values`, and `ValuesMut` iterators to `ClockRing`, allowing for flexible and efficient iteration over entries, keys, and values. - Updated documentation to include new iterator methods and examples, improving clarity and user guidance. - Enhanced the operation table to reflect the addition of iteration capabilities, ensuring comprehensive API coverage.
- Resolved TOCTOU race conditions in `ConcurrentSlabStore` by consolidating `RwLock`s for atomicity during updates and removals. - Fixed ARC ghost-list directory leak to maintain invariant bounds during eviction. - Updated capacity handling in `Clock`, `ClockPro`, and `NRU` policies to reject zero capacity inserts gracefully. - Unified `CoreCache::insert` behavior across `MRU`, `SLRU`, and `TwoQ` policies for consistency. - Added metrics tracking for `ConcurrentWeightStore` operations. - Introduced new `GhostList::evict_lru()` method and iterators for `ClockRing`, along with integration tests for concurrency and policy invariants. - Updated `ClockRing` documentation with improved clarity and expanded operations table.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This branch fixes several correctness bugs discovered across cache policies and concurrent stores, and adds regression tests to prevent recurrence.
Bug Fixes
ConcurrentSlabStore TOCTOU race conditions — The old design used three separate
RwLocks (for index, entries, and free list), creating time-of-check-to-time-of-use windows that could cause data corruption on concurrent update-after-remove, capacity overshoot under parallel inserts, and half-cleared state visible to readers duringclear(). Refactored into a singleSlabInnerstruct behind oneRwLockto ensure atomicity across all mutations.ARC ghost-list directory leak — The Case 4 (complete miss) path was not properly pruning ghost lists B1/B2, violating the ARC paper's invariant that directory size (T1+T2+B1+B2) ≤ 2×capacity. Fixed to match the paper's eviction logic and added
GhostList::evict_lru()to support it.Capacity-0 coercion in Clock, ClockPro, NRU — These policies silently coerced
capacity=0tocapacity=1via.max(1)in their constructors, inconsistent with the rest of the library. Now they honorcapacity=0and reject inserts gracefully.MFU insert return-value bug —
MfuCore::insertatcapacity=0returnedSome(value)(echoing the value back) instead ofNone. Fixed to returnNonefor rejected inserts.MRU / SLRU / TwoQ
CoreCache::insertinconsistency — TheCoreCachetrait impl duplicated update-in-place logic that diverged from each type's inherentinsertmethod. Unified by having the trait impl delegate directly to the inherent method. The inherentinsertnow returnsOption<V>(old value on update,Noneon fresh insert).ConcurrentWeightStore missing metrics —
try_insertandremovedelegated to the inner store without updating the external metrics counters for inserts, updates, and removes.Enhancements
Iter,IterMut,IntoIter,Keys,Values,ValuesMutandIntoIteratorimpl forClockRing.Tests Added
tests/slab_concurrency.rs— Integration tests for TOCTOU update corruption, capacity overshoot, and atomicclear()under concurrency.tests/policy_invariants.rs— Cross-policy invariant tests for capacity-0 semantics (Clock, ClockPro, NRU).ConcurrentWeightStoremetrics tracking tests for inserts, updates, removes, hits, and misses.Type of Change
How Has This Been Tested?
Checklist
cargo test)